@extends('layouts.layouts')
@section('title')
    <title>后台首页</title>
    <style>
        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }
        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }
    </style>
@endsection
@section('content')
    <link href="/lib/ueditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" charset="utf-8" src="/lib/ueditor/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/ueditor/umeditor.min.js"></script>
    <script type="text/javascript" src="/lib/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script src="/js/upload.js" type="text/javascript"></script>
    <script src="/js/mobileBUGFix.mini.js" type="text/javascript"></script>
    <link href="/css/ueditor.css" type="text/css" rel="stylesheet">
    <div class="content">
        <div class="header">
            <ul class="breadcrumb">
                <li><a href="/article/list">文章列表</a> </li>
                <li class="active">添加信息</li>
            </ul>
        </div>
        <div class="main-content">
            <ul class="nav nav-tabs nav-tabs-course">
                <li role="presentation" class="course_add active"><a href="javascript:void(0);">添加信息</a></li>
                <!-- <li role="presentation" class="course_hour_add"><a href="javascript:void(0);">课时添加</a></li> -->
            </ul>
            <form class="form-horizontal" id="courseFormInfo" action="/article/insert" method="post">
                {{csrf_field()}}
                <div class="course_class row">
                    <div class="col-md-10">
                            <br>
                            <div class="tab-content">
                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">文章/视频</label>
                                    <div class="col-sm-4">
                                        <select class="form-control is_video" name="is_video">
                                            <option value="0" selected>文章</option>
                                            <option value="1">视频</option>
                                        </select>
                                    </div>
                                </div>
                                
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-3 control-label">信息名称</label>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control" name="title" placeholder="文章名称">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">信息配图(大小500kb)</label>
                                    <div class="col-sm-9">

                                        <a href="javascript:;" class="file">上传封面图(640X360)
                                            <input type="file" class="upload_img cover" name="coverUrl" placeholder="封面图">
                                        </a>
                                        <!-- <a href="javascript:;" class="file">上传说明图(750X300)
                                            <input type="file" class="upload_img explain" name="explainUrl" placeholder="说明图">
                                        </a> -->
                                        <img src="" id="cover_img" style="width:120px;max-height:120px;">
                                        <!-- <img src="" id="explain_img" style="width:120px;max-height:120px;"> -->
                                        <input type="hidden" class="cover_img" name="cover_url" />
                                        <!-- <input type="hidden" class="explain_img" name="explainImg" /> -->
                                        <span id="error"></span>
                                    </div>
                                </div>
                                    

                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">海报图片(大小500kb)</label>
                                    <div class="col-sm-9">
                                        <a href="javascript:;" class="file">上传封面图()
                                            <input type="file" class="upload_img1 bill" name="bill_img" placeholder="封面图">
                                        </a>
                                        <img src="" id="bill_img" style="width:120px;max-height:120px;">
                                        <input type="hidden" class="bill_img" name="bill_img" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    
                                    <label for="inputEmail3" class="col-sm-3 control-label">精选日期</label>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control" name="today_selected" placeholder="精选日期" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"  />
                                    </div>
                                </div>    

                                <div class="form-group" id="video_url" style="display: none;">
                                    <label for="inputEmail3" class="col-sm-3 control-label">视频地址<span style="color:red;">*</span></label>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control" name="video_url" placeholder="视频地址">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-3 control-label">信息排序值</label>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control" value="20" name="orderby" placeholder="信息排序值">
                                        
                                    </div>
                                    <b>(课程显示排序值从大到小排序,最小为0)</b>
                                </div>
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-3 control-label">喜欢人数</label>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control" value="20" name="likes" placeholder="喜欢人数"> 
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-3 control-label">浏览人数</label>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control" value="20" name="views" placeholder="浏览人数"> 
                                    </div>
                                </div>
                                
                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">信息类别</label>
                                    <div class="col-sm-9">
                                        @foreach($types as $type)
                                        <label class="checkbox-inline">
                                            <input type="checkbox" name="types[]" value="{{$type->id}}">{{$type->title}}
                                        </label>
                                        @endforeach
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">信息标签</label>
                                    <div class="col-sm-9">
                                        @foreach($tags as $tag)
                                        <label class="checkbox-inline">
                                            <input type="checkbox" name="tags[]" value="{{$tag->id}}">{{$tag->title}}
                                        </label>
                                        @endforeach
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">专题类别</label>
                                    <div class="col-sm-9">
                                        @foreach($special as $v)
                                        <label class="checkbox-inline">
                                            <input type="checkbox" name="special_id[]" value="{{$v->id}}">{{$v->title}}
                                        </label>
                                        @endforeach
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">作者</label>
                                    <div class="col-sm-9">
                                        <button type="button" class="btn btn-primary btn-lg" data-page="1" onclick="selectAuthor(this);">选择</button>&nbsp;&nbsp;<span style="color:blue;" id="userName"></span>
                                        <input type="hidden" class="form-control" value="" id="inputPassword3" name="author">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">是否为用户投稿</label>
                                    <div class="col-sm-4">
                                        <select class="form-control" name="is_recommend">
                                            <option value="0" selected>否</option>
                                            <option value="1">是</option>
                                        </select>
                                    </div>
                                    <b>(意思指该文章是用户投稿文章，默认为不是)</b>
                                </div>
                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">文章简介</label>
                                    <div class="col-sm-8">
                                        <textarea type="text/plain" class="form-control" placeholder="例如：课程精细讲解背部构造知识，让您拥有专属于自己的背部方案，练就姿态挺拔的强大气质" id="description" name="description"></textarea>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-3 control-label">seo标题</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="seo_title" placeholder="seo标题">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-3 control-label">seo描述</label>
                                    <div class="col-sm-8">
                                        <textarea type="text/plain" class="form-control" placeholder="seo描述" name="seo_description"></textarea>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">文章内容</label>
                                    <div class="col-sm-9">
                                        <textarea type="text" name="content" id="myEditor" style="width:700px;height:240px;" ></textarea>
                                    </div>
                                </div>
                            </div>
                    </div>
                </div>
                <div class="row">
                    <p>
                        <button type="submit" class="btn btn-primary col-md-offset-5" style="width:120px;background:#286090;color:#fff;">提交</button>
                    </p>
                </div>
            </form>
            <br/>
            <br/>    
        </div>
    </div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">选择作者</h4>
                </div>
                <div class="modal-body"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
    <script src="/js/ueditor.js"></script>
    <script src="/js/course.js"></script>
    <script src="/lib/jquery.validate.js" type="text/javascript"></script>
    <script>

        $(document).ready(function(){
            $(".is_video").change(function() {
                var value = $(this).val();
                if(value){
                    $("#video_url").show();
                }else{
                    $("#video_url").hide();
                }
            });
        });

        var imgUrl = '{{env('IMG_URL')}}';
        $(".upload_img").UploadImg({
            url : '/course/fileUpload',
            // width : '320',
            //height : '200',
            quality : '0.8', //压缩率，默认值为0.8
            // 如果quality是1 宽和高都未设定 则上传原图
            mixsize : '500000',
            //type : 'image/png,image/jpg,image/jpeg,image/pjpeg,image/gif,image/bmp,image/x-png',
            before : function(blob,className){
//                var className = '#'+className;
//                $(className).attr('src',blob);
            },
            error : function(res){
                $('#img').attr('src','');
                $('#error').html(res);
            },
            success : function(url,className){
                var idName = '#'+className;
                var className = '.'+className;
                $(idName).attr('src',imgUrl+url);
                $(className).val(url);
            }
        });
        $(".upload_img1").UploadImg({
            url : '/course/fileUpload',
            // width : '320',
            //height : '200',
            quality : '0.8', //压缩率，默认值为0.8
            // 如果quality是1 宽和高都未设定 则上传原图
            mixsize : '500000',
            //type : 'image/png,image/jpg,image/jpeg,image/pjpeg,image/gif,image/bmp,image/x-png',
            before : function(blob,className){
//                var className = '#'+className;
//                $(className).attr('src',blob);
            },
            error : function(res){
                $('#img').attr('src','');
                $('#error').html(res);
            },
            success : function(url,className){
                var idName = '#'+"bill_img";
                var className = '.'+"bill_img";
                $(idName).attr('src',imgUrl+url);
                $(className).val(url);
            }
        });
        $("#courseFormInfo").validate({
            onsubmit: true,// 是否在提交是验证
            submitHandler: function (form) {
                var title = $("input[name='title']").val();
                var types = $("input[name='types[]']:checked").val();
                var tags = $("input[name='tags[]']:checked").val();
                //var cover_url = $("input[name='cover_url']").val();
                var description = $("#description").val();
                var seo_title   = $("input[name='seo_title']").val();
                var seo_description   = $("input[name='seo_description']").val();
                if(title == ''){
                    swal("文章名称未录入!");
                    return false;
                }
                if(!types){
                    swal("未选择信息分类!");
                    return false;
                }
                if(!tags){
                    swal("未选择标签");
                    return false;
                }
                // if(cover_url == ''){
                //     swal("未上传封面图");
                //     return false;
                // }
                
                if(description == ''){
                    swal('未填写描述');
                    return false;
                }
                if(seo_title == ''){
                    swal('未填写seo_标题');
                    return false;
                }
                if(seo_description == ''){
                    swal('未填写seo_描述');
                    return false;
                }
                form.submit();
            }
        });
    </script>
    <style type="text/css">
        .col-sm-2{
            width:60px;
        }
        .course_content{
            margin-right: -30px;
            margin-left: -30px;
            margin-top:5px;
        }
        .btn-success{
            background-image:none!important;
        }
    </style>
@endsection